import App from '@/App.vue'

const http = uni.$u.http
// 项目ID
const project_id = App.globalData.project_id

export default {
	/**
	 * 添加商品到购物车
	 *  - post请求
	 */
	addGoodToCartAPI: (data) => {
		return http.post('/shoppingCart', {
			project_id,
			goods_id: data.goods_id,
			num: data.num
		}, {
			custom: {
				auth: true
			}
		});
	},

	/**
	 * 获取自己的购物车信息
	 *  - get请求
	 */
	getGoodsInCartAPI: () => {
		return http.get('/shoppingCart', {
			params: {
				project_id
			},
			custom: {
				auth: true
			},
		});
	},

	/**
	 * 更新购物车内某条商品
	 *  - put请求
	 */
	updateCartAPI: (id, num) => {
		return http.put('/shoppingCart/' + id, {
			num
		}, {
			custom: {
				auth: true,
				toast: true
			}
		});
	},

	/**
	 * 删除购物车的一条商品
	 *  - delete请求
	 */
	deleteGoodInCartAPI: (id) => {
		return http.delete('/shoppingCart/' + id, {
			project_id
		}, {
			custom: {
				auth: true,
				toast: true
			}
		});
	}
}